package com.itheima.thread.utils.cyclibarrier.demo01;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierThread01 extends Thread {

    private CyclicBarrier cyclicBarrier;
    public CyclicBarrierThread01(CyclicBarrier cyclicBarrier){
        this.cyclicBarrier = cyclicBarrier;
    }

    @Override
    public void run() {
        for (int i = 0; i < 101; i++) {
            System.out.println("CyclicBarrierThread01----" + i);
            if (i == 20){
                System.out.println("CyclicBarrierThread01到达了屏障点....");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
